package edu.hnnu.sport_event.service;

import edu.hnnu.sport_event.entity.Student;
import edu.hnnu.sport_event.entity.User;
import edu.hnnu.sport_event.mapper.StudentMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class StudentServiceImp implements StudentService {

    @Resource
    StudentMapper mapper;

    @Override
    public int login(User user) {
        Student _student = mapper.select(user.getUsername());
        // 未注册
        if (_student == null) return -2;
        // 登录成功
        if (user.getPassword().equals(_student.getPassword())) { return _student.getId(); }
        // 登录失败，密码错误
        return -1;
    }

    public String getStudentName(int id) {
        return mapper.getName(id);
    }

    public Student getStudentById(int id) {
        return mapper.selectById(id);
    }

    public int updateStudent(Student student) {
        return mapper.update(student);
    }

}
